package com.parkinglot.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.parkinglot.core.Result;
import com.parkinglot.parmeter.AdvertaddParm;
import com.parkinglot.parmeter.AdvertqueryParm;
import com.parkinglot.parmeter.AdvertupdParm;
import com.parkinglot.parmeter.UserqueryParm;
import com.parkinglot.pojo.AdvertRecord;
import com.parkinglot.service.AdvertRecordService;
import com.parkinglot.service.AdvertService;
import com.parkinglot.util.ImgUtils;
import com.parkinglot.vo.AdvertCountVo;
import com.parkinglot.vo.AdvertqueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("garageadvert")
@Api(tags = "车库广告接口")
@Slf4j
public class GarageAdvertController {

    @Resource
    private AdvertService advertService;
    @Resource
    private AdvertRecordService advertRecordService;
    @Resource
    private ImgUtils imgUtils;

   /* @ApiOperation(value = "新增广告")
    @PostMapping("/addadvert")
    public Result addadvert(AdvertaddParm advertaddParm, @RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request){
        return Result.success(advertService.addadvert(advertaddParm,files,request));
    }*/
    @ApiOperation(value = "新增广告")
    @PostMapping("/addadvert")
    public Result addadvert(AdvertaddParm advertaddParm){
        return Result.success(advertService.addadvert(advertaddParm));
    }

    @ApiOperation(value = "修改广告")
    @PostMapping("/updadvert")
    public Result updadvert(AdvertupdParm advertupdParm){
        return Result.success(advertService.update(advertupdParm));
    }

    @ApiOperation(value = "广告位统计（统计哪个车库哪个广告位访问次数及时间段信息）")
    @GetMapping("/countadvertnum")
    public Result countadvertnum(){
        return Result.success(advertService.countadvertnum());
    }

    @ApiOperation(value = "广告位访问记录（哪个用户什么时候访问了哪个广告位）")
    @GetMapping("/advertrecord")
    public Result advertrecord(UserqueryParm userParm){
        return Result.success(advertRecordService.advertrecord(userParm));
    }

  /*  @ApiOperation(value = "所有广告投放数或某个车库广告投放数")
    @GetMapping("/countadvert")
    public Result countadvert(AdvertqueryParm advertqueryParm){
        return Result.success(advertRecordService.countadvert(advertqueryParm));
    }*/

    @ApiOperation(value = "某个停车场下广告")
    @GetMapping("/garageradvert")
    public Result garageradvert(AdvertqueryParm advertqueryParm){
        return Result.success(advertRecordService.garageradvert(advertqueryParm));
    }

    @ApiOperation(value = "分页查询某车库广告")
    @GetMapping("/advertpage")
    public Result advertpage(AdvertqueryParm advertqueryParm,int pageNum ,int pageSize ){


         List<AdvertCountVo>list= advertRecordService.garageradvert(advertqueryParm);
        PageHelper.startPage(pageNum, list.size());
        return Result.success(new PageInfo<AdvertCountVo>(list));
    }

    @ApiOperation(value = "某车库下昨日所有广告点击率")
    @GetMapping("/garageadverdjv")
    public Result garageadverdjv(AdvertqueryParm advertqueryParm ){
        return Result.success(advertService.garageadverdjv(advertqueryParm));
    }

    @ApiOperation(value = "某车库下上周所有广告点击率")
    @GetMapping("/advertweekdjv")
    public Result advertweekdjv(AdvertqueryParm advertqueryParm ){
        return Result.success(advertService.advertweekdjv(advertqueryParm));
    }

    @ApiOperation(value = "某车库下上月所有广告点击率")
    @GetMapping("/advertmonthdjv")
    public Result advertmonthdjv(AdvertqueryParm advertqueryParm ){
        return Result.success(advertService.advertmonthdjv(advertqueryParm));
    }

    @ApiOperation(value = "某车库下广告分页查询投放记录")
    @GetMapping("/garagepagerecord")
    public Result advertpagerecord(AdvertqueryParm advertqueryParm ,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<AdvertqueryVo> advertpagerecord = advertService.advertpagerecord(advertqueryParm);
        return Result.success(new PageInfo<AdvertqueryVo>(advertpagerecord));
    }

    @ApiOperation(value = "所有车库昨日点击率")
    @GetMapping("/allgaragezrdjv")
    public Result allgaragezrdjv(){
        return Result.success(advertService.allgaragezrdjv());
    }

    @ApiOperation(value = "所有车库上周点击率")
    @GetMapping("/allgarageszdjv")
    public Result allgarageszdjv(){
        return Result.success(advertService.allgarageszdjv());
    }

    @ApiOperation(value = "所有车库上月点击率")
    @GetMapping("/allgaragesydjv")
    public Result allgaragesydjv(){
        return Result.success(advertService.allgaragesydjv());
    }

    @ApiOperation(value = "手机端用户点击广告添加广告次数")
    @PostMapping("/addadvertrecord")
    public Result addadvertrecord(@RequestBody AdvertRecord advertRecord){
        return Result.success(advertRecordService.insert(advertRecord));
    }

    @ApiOperation(value = "上传广告图片")
    @PostMapping("/uploadimage")
    public Result uploadimage(@RequestParam(value = "file") MultipartFile[] files,HttpServletRequest request){
        List<String> imagepath= imgUtils.getOrderDtl(files,request);
        return Result.success(imagepath);
    }

}
